{include file="common/head"/}
<style>
    .layui-table-cell{height: auto;}
    .layui-table-cell ul li a{color: #1C8FEF;display: block;border: 1px solid #ececec;padding: 3px 8px;}
    .layui-table-cell ul li a:hover{color: #005580}
</style>
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>周期列表</legend>
    </fieldset>
    <!--<blockquote class="layui-elem-quote">-->
        <!--<a id="add" class="layui-btn layui-btn-sm">添加周期</a>-->
        <!--&lt;!&ndash; <a href="{:url('manage')}" class="layui-btn layui-btn-sm">re</a>&ndash;&gt;-->
    <!--</blockquote>-->
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
<script type="text/html" id="status">
    <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="status" {{ d.status == 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="barDemo">
    <a data-id="{{d.id}}" class="layui-btn layui-btn-xs edit-section">{:lang('edit')}</a>
</script>

{include file="common/foot"/}
<script>
    layui.use(['table','form'], function() {
        var table = layui.table,form = layui.form, $ = layui.jquery;
        // 渲染表格
        table.render({
            id: 'user',
            elem: '#list',
            url: "{:url('lists')}",
            method: 'post',
            even:true,
            cols: [[
                {field: 'title', title: '周期名称', width: 120}
                , {field: 'start_time', title: '考核开始时间', width: 300}
                , {field: 'end_time', title: '考核结束时间', width: 300}
                ,{field: 'status', align: 'center', title: '启用状态', width: 200, toolbar: '#status'}
                , {field: 'update_time', title: '更新时间', width: 200}
                ,{width: 100, align: 'center', toolbar: '#barDemo'}
            ]]
        });

        form.on('switch(status)', function(obj){
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var id = this.value;
            var status = obj.elem.checked===true?1:0;
            $.post('{:url("cycleState")}',{'id':id,'status':status},function (res) {
                layer.close(loading);
                if (res.code==1) {
                    layer.msg(res.msg,{time:1000,icon:1});
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                    return false;
                }
            })
        });
        // 修改部门
        $(document).on('click','.edit-section',function () {
            var id=$(this).attr('data-id');
            layer.open({
                type:2,
                title: '编辑周期',
                shadeClose:true,
                shade:0.3,
                area:['600px','420px'],
                content: '{:url("cycleEdit")}?cycle_id='+id
            });
        });
        // 新增部门
        $('#add').on('click',function () {
            layer.open({
                type:2,
                title: '添加周期',
                shadeClose:true,
                shade:0.3,
                area:['600px','420px'],
                content: '{:url("cycleAdd")}'
            });
        });
    });
</script>
</body>
</html>